#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 200010;
const int maxm = 1000010;
int n,m,father[2*maxn],ans[maxn];
struct node{
	int a,b,c;
}gx[maxm];

bool cmp(const node &a,const node &b){
	return a.c>b.c;
}

void init(){
	for(int i=1;i<=2*n;i++)father[i]=i;
}

int find(int x){
	if(father[x]==x)return x;
	father[x]=find(father[x]);
	return father[x];
}

void merge(int x,int y){
	int f1 = find(x);
	int f2 = find(y);
	if(f1 != f2)	father[f1] = f2;
}

int main(){

	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d %d %d",&gx[i].a,&gx[i].b,&gx[i].c);
	}
	init(); 
	sort(gx+1,gx+m+1,cmp);
	int cnt = 0;
	for(int i=1;i<=m;i++){
		int a = find(gx[i].a);
		int b = find(gx[i].b);
		if(a == b)ans[++cnt] = gx[i].c;
		else{
			merge(gx[i].a+n,gx[i].b);
			merge(gx[i].a,gx[i].b+n);
		}
	}
	sort(ans+1,ans+1+cnt);
	printf("%d\n",ans[cnt]);
	return 0;
	
}
